﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.TcCommands.TcReloadResource.CCoTcReloadResourceCmdEnabler
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using UiInternalControls;


namespace DnProcessSimulateCommands.TcCommands.TcReloadResource;

public class CCoTcReloadResourceCmdEnabler : ITxCommandEnabler
{
  public bool Enable => this.ShouldEnable();

  private bool ShouldEnable()
  {
    bool flag = false;
    if (this.IsSupportedByPlatform)
    {
      TxObjectList allItems = TxApplication.ActiveSelection.GetAllItems();
      flag = ((Collection<ITxObject>) allItems).Count > 0;
      for (int index = 0; index < ((Collection<ITxObject>) allItems).Count & flag; ++index)
      {
        ITxObject itxObject = ((Collection<ITxObject>) allItems)[index];
        if (!TxEngineeringDataInternal.ObjectIsResourceInstance(itxObject))
          flag = false;
        else if (TcCommandsUtility.IsEquipment(itxObject) && TcCommandsUtility.IsUnderEquipment(itxObject))
          flag = false;
        else if (TcCommandsUtility.IsPrototypeAssignment(itxObject))
          flag = false;
        if (itxObject is ITxComponent itxComponent && itxComponent.RepresentationType == 6)
          flag = false;
      }
    }
    return flag;
  }

  private bool IsSupportedByPlatform
  {
    get
    {
      return TxTcUtilities.IsTcOnlinePlatform && TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoadedFromFile() && !TxTcStudyReservation.IsReadOnly();
    }
  }
}
